// /*

//   Shennong.ino

//   Scroll through Chinese Short Story
//   "The Farmer God Shen Nong Tastes All the Plants"

//   U8g2_for_TFT_eSPI:
//     - Use U8g2 fonts with TFT_eSPI
//     - Support for UTF-8 in print statement
//     - 90, 180 and 270 degree text direction

//   List of all U8g2 fonts:    https://github.com/olikraus/u8g2/wiki/fntlistall

//   TFT_eSPI library:          https://github.com/Bodmer/TFT_eSPI
//   U8g2_for_TFT_eSPI library: https://github.com/Bodmer/U8g2_for_TFT_eSPI


//   English translation:
//   The Farmer God Shen Nong Tastes All the Plants

//   Source:
//   http://chinesereadingpractice.com/2012/08/22/the-farmer-god-shen-nong-tastes-all-the-plants/

//   All his life, Shen Nong had a crystal abdomen, and one could
//   clearly see all of his internal organs. At that time, humans were
//   often getting sick and even dying because they ate things
//   indiscriminately [not knowing if they were good or bad]. Shen
//   Nong determinedly tasted everything everywhere; the
//   good-tasting things he put in a bag on his left side, those were
//   for people to eat; the bad-tasting things he put in a bag on his
//   right side, and those were used for medicine.

//   The first time, Shen Nong tasted a small fresh leaf. As this leaf
//   fell into his stomach, it cleaned every inch of his insides so that
//   every organ top and bottom was fresh and cool, as if [the leaf]
//   was somehow on patrol [making the rounds], so Shen Nong
//   called it “chá�? [to investigate / check], and later generations of
//   men called it “chá�? [tea]. Shen Nong put it in the bag on the
//   right. The second time, Shen Nong tasted a little light red flower
//   that looked like a butterfly, which was sweet and delicious, with
//   an exotic smell that filled his nostrils, so he called it “licorice�?. He
//   put it in the bag on the left. In this way, Shen Nong diligently
//   tasted all manner of flora, and every time he was poisoned, he
//   used tea to rescue himself. Before long, the bag on his left
//   contained 47,000 kinds of flowers, grasses, roots and leaves,
//   and the right side had 398,000 kinds.

//   But one day, Shen Nong tasted “heartbreak grass�?, and this
//   poison was too terrible, so there wasn’t enough time to eat the
//   tea leaves to detoxify and he died. He sacrificed himself to save
//   humanity, so people call him the “Bodhisattva of Medicine�?, and
//   people forever commemorate him through this story.


// */
// // #include <stdint.h>
// #include "SPI.h"
// #include "TFT_eSPI.h"
// #include <TimeLib.h>
// #include "U8g2_for_TFT_eSPI.h"

// #ifdef ESP8266
// #include <ESP8266WiFi.h>
// #include <ESP8266HTTPClient.h>
// #include <ESP8266WiFiMulti.h>
// #include <WiFiClientSecureBearSSL.h>
// #else
// #include <WiFi.h>
// #include <HTTPClient.h>
// #endif

// #include "WMHelper.h"
// #include "TimeUtil.h"
// #include "Weather.h"

// #include <TJpg_Decoder.h>
// #include "img/pangzi/i0.h"
// #include "img/pangzi/i1.h"
// #include "img/pangzi/i2.h"
// #include "img/pangzi/i3.h"
// #include "img/pangzi/i4.h"
// #include "img/pangzi/i5.h"
// #include "img/pangzi/i6.h"
// #include "img/pangzi/i7.h"
// #include "img/pangzi/i8.h"
// #include "img/pangzi/i9.h"
// #include "img/panda.h"

// TFT_eSPI tft = TFT_eSPI(); // tft instance
// U8g2_for_TFT_eSPI u8f;     // U8g2 font instance

// // To read the short story with all glyphs you need at least a font with _gb2312b postfix
// // However, a font with _gb2312b postfix is very large and will not always fit on
// // the target controller. For testing you can use _chinese1 extension, but then
// // many glyphs are skipped and not visible.
// //
// // wqy fonts are available in different sizes, here are only wqy12, wqy14 and wqy16 listed

// // #define FONT u8g2_font_wqy12_t_chinese1
// #define FONT u8g2_font_wqy12_t_gb2312b

// //#define FONT u8g2_font_wqy14_t_chinese1
// //#define FONT u8g2_font_wqy14_t_gb2312b

// //#define FONT u8g2_font_wqy16_t_chinese1
// // #define FONT u8g2_font_wqy16_t_gb2312b

// // The next two macros define the scroll speed of the short story
// #define SCROLL_DELTA 4
// #define SCROLL_DELAY 100

// time_t prevDisplay = 0; // 显示时间
// time_t weaterTime = 0;  // 显示天气


// time_t getNtpTime();

// long lastMqttConn = 0;
// void checkNetStatus()
// {
//   // Wifi掉线重连
//   if (WiFi.status() != WL_CONNECTED)
//   {
//     connectWifi();
//   }

//   //非阻塞Mqtt重连，间隔30秒
//   if (WiFi.status() == WL_CONNECTED)
//   {
//     long now = millis();
//     if (!mqttClient.connected())
//     {
//       if (now - lastMqttConn > 30000)
//       {
//         lastMqttConn = now;
//         connectMqtt();
//       }
//     }
//     else
//     {
//       mqttClient.loop();
//     }
//   }
// }

// /**
//  * 表盘
//  */
// void setUpClock()
// {
//   setSyncProvider(getNtpTime);
//   setSyncInterval(300);

//   //背景
//   tft.fillRect(0, 55, 128, 30, TFT_WHITE);
//   //  tft.drawLine(0, 40, 128, 40, TFT_BLACK);
//   //时间区域（0,40：128,120）
//   u8f.setFont(u8g2_font_osr21_tf);
//   u8f.drawUTF8(5, 80, (hourMinute() + ":" + num2str(second())).c_str());
//   tft.drawLine(0, 120, 128, 120, TFT_BLACK);
// }
// /**
//  * 显示天气
//  */
// void setupWeather(WeatherData weatherData)
// {
//   // //背景
//   // tft.fillRoundRect(0, 0, 128, 160, 5, TFT_WHITE);
//   //天气区域（0，0：84,40）
//   u8f.setFont(FONT);
//   u8f.setForegroundColor(TFT_BLACK); // apply color
//   u8f.setBackgroundColor(TFT_WHITE); // apply color
//   // u8f.set
//   u8f.drawUTF8(5, 20, weatherData.weather.c_str());
//   // u8f.setCursor(5,5);                // start writing at this position
//   // u8f.print("天气");
//   tft.drawLine(0, 40, 128, 40, TFT_BLACK);
//   //地方区域（84，0：128,40）
//   u8f.drawUTF8(90, 20, weatherData.cityName.c_str());
//   tft.drawLine(84, 0, 84, 40, TFT_BLACK);
//   //时间区域（0,40：128,120）
//   //星期区域（0,120:38，160）

//   u8f.drawUTF8(5, 145, week().c_str());
//   tft.drawLine(38, 120, 38, 160, TFT_BLACK);
//   //日期区域（38,120:128,160）
//   u8f.drawUTF8(40, 145, monthDay().c_str());
//   tft.drawLine(88, 120, 88, 160, TFT_BLACK);
//   //温度区域（88,120:128,160）
//   u8f.drawUTF8(93, 145, weatherData.temp.c_str());
// }
// /**
//  * 太空人图片
//  */
// void imgAnim()
// {
//   int x = 50, y = 80, dt = 10; //瘦子版dt=10毫秒 胖子30较为合适

//   delay(dt);
//   TJpgDec.drawJpg(x, y, i1, sizeof(i1));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i2, sizeof(i2));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i3, sizeof(i3));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i4, sizeof(i4));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i5, sizeof(i5));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i6, sizeof(i6));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i7, sizeof(i7));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i8, sizeof(i8));
//   delay(dt);
//   TJpgDec.drawJpg(x, y, i9, sizeof(i9));
//   delay(dt);
// }
// bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
// {
//   if (y >= tft.height())
//     return 0;
//   tft.pushImage(x, y, w, h, bitmap);
//   // Return 1 to decode next block
//   return 1;
// }
// /**
//  *
//  *图片解码初始化
//  */
// void setupJpg()
// {
//   TJpgDec.setJpgScale(2);
//   TJpgDec.setSwapBytes(true);
//   TJpgDec.setCallback(tft_output);
// }
// Weather weather;
// void setup()
// {
//   tft.begin();
//   tft.setRotation(0);
//   tft.fillScreen(TFT_WHITE);
//   u8f.begin(tft); // connect u8g2 procedures to TFT_eSPI
//   Serial.begin(115200);
//   // // setupJpg();
//   // printMsg("wumei smart device starting...");
//   //背景
//   tft.fillRoundRect(0, 0, 128, 160, 5, TFT_WHITE);
//   connectWifi();
//   setUpClock();
//   // publishNtp();
//   // getTime();

//   setupWeather(weather.getCityWeater());

//   //图片区域（0,80：128,120）
//   // TJpgDec.drawJpg(0, 80, panda, sizeof(panda));

// // Initialise SPIFFS
//   if (!SPIFFS.begin(true)) {
//     Serial.println("SPIFFS initialisation failed!");
//     while (1) yield(); // Stay here twiddling thumbs waiting
//   }
//   Serial.println("\r\nInitialisation done.");
//   uint16_t w = 0, h = 0;
//   TJpgDec.getFsJpgSize(&w, &h, "/panda.jpg"); // Note name preceded with "/"
//   Serial.print("Width = "); Serial.print(w); Serial.print(", height = "); Serial.println(h);

//   // Draw the image, top left at 0,0
//   TJpgDec.drawFsJpg(0, 0, "/panda.jpg");


// }

// void loop()
// {
//   // imgAnim();
//   // setUpClock();
//   // delay(SCROLL_DELAY);

//   // checkNetStatus();

//   // if (now() != prevDisplay)
//   // {
//   //   prevDisplay = now();
//   //   setUpClock();
//   // }
//   // if (millis() - weaterTime > 300000)
//   // { // 5分钟更新一次天气
//   //   weaterTime = millis();
//   //   setupWeather(weather.getCityWeater());
//   // }
// }
